﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAO;
using System.Web.Security;
namespace ProyectoCine.AreaPrivada
{
    public partial class Salas : System.Web.UI.Page, IGrilla
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!Page.IsPostBack)
            {
                ViewState["Orden"] = "";
                cargarGrilla();
            }
        }

        protected void idBuscar_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtBuscar.Text))
            {
                gvSalas.DataSource = SalaDAO.cargarGrillaNombre(txtBuscar.Text);
                gvSalas.DataBind();
            }
            else
            {
                cargarGrilla();
            }
        }

        protected void gvSalas_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (gvSalas.SelectedIndex == -1) return;
            Session["numero_SalaEdicion"] = gvSalas.SelectedDataKey.Value;
            Response.Redirect("AltaSala.aspx");

        }

        public void cargarGrilla()
        {
            gvSalas.DataKeyNames = new string[] { "numero_Sala" };
            gvSalas.DataSource = SalaDAO.cargarGrilla(ViewState["Orden"].ToString());
            gvSalas.DataBind();
        }

        protected void gvSalas_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvSalas.PageIndex = e.NewPageIndex;
            cargarGrilla();
        }

        protected void gvSalas_Sorting(object sender, GridViewSortEventArgs e)
        {
            ViewState["Orden"] = e.SortExpression;
            cargarGrilla();
        }
    }
}